package jwdt.xadmin.work.action;

import jwdt.common.action.BaseAction;
import jwdt.xadmin.system.bean.TUser;
import jwdt.xadmin.work.bean.TTaskLog;
import jwdt.xadmin.work.service.TaskLogManageService;

import com.ezerg.db.ext.PageUtil;
import com.ezerg.web.Form;
import com.ezerg.web.Module;
import com.ezerg.web.Page;
import com.ezerg.web.annotation.Controller;
import com.ezerg.web.annotation.RequestMapping;

@Controller("/xadmin/work")
public class TaskLogManagerAction extends BaseAction {

	private TaskLogManageService tasklogManageService = (TaskLogManageService)app.getBean("tasklogManageService");
	
	@RequestMapping("/listTaskLog")
	public Page doListTask(Form f, Module m) throws Exception {
		PageUtil pu = (PageUtil)f.copy2Class(PageUtil.class);
		int taskid = f.getInt("taskid");
    	return m.getWritePage(f, tasklogManageService.doList(pu,taskid).toJson());
	}
	
	@RequestMapping("/listMyTaskLog")
	public Page doMyListTask(Form f, Module m) throws Exception {
		PageUtil pu = (PageUtil)f.copy2Class(PageUtil.class);
		TUser userInfo = (TUser) f.getSession("userInfo");
		TTaskLog obj = (TTaskLog)f.copy2Class(TTaskLog.class);
		int projectId = f.getInt("projectId");
    	return m.getWritePage(f, tasklogManageService.doList(pu,userInfo,obj,projectId).toJson());
	}
	
	@RequestMapping("/addTaskLog")
	public Page doAddact(Form f, Module m) throws Exception {
		TTaskLog obj = (TTaskLog)f.copy2Class(TTaskLog.class);
		TUser userInfo = (TUser) f.getSession("userInfo");
		return m.getWritePage(f, tasklogManageService.doAddact(obj,userInfo));
	}
	
	@RequestMapping("/editTaskLog")
	public Page doEditact(Form f, Module m) throws Exception {
		int logid = f.getInt("logid"); 
		TTaskLog obj = (TTaskLog)f.copy2Class(TTaskLog.class);
		return m.getWritePage(f, tasklogManageService.doEditact(obj, logid));
	}
	
	@RequestMapping("/delTaskLog")
	public Page doDel(Form f, Module m) throws Exception {
		int tasklogid = f.getInt("tasklogid");
		return m.getWritePage(f, tasklogManageService.doDelact(tasklogid));
	}
	
	@RequestMapping("/taskLogManage")
	public Page doLoad(Form f, Module m) throws Exception {
		int taskid = f.getInt("taskid");
		f.add("obj", tasklogManageService.doLoad(taskid,true));
		return m.findPage("/xadmin/work/taskLogManage");
	}
	
	@RequestMapping("/updateTaskLogState")
	public Page doUpdateState(Form f, Module m) throws Exception {
		int logid = f.getInt("logid");
		String result = f.getString("result");
		return m.getWritePage(f, tasklogManageService.doUpdateState(logid,result));
	}
	
	@RequestMapping("/mytaskWindow")
	public Page doMytaskWindow(Form f, Module m) throws Exception {
		int logid = f.getInt("logid");
		int zt = f.getInt("zt");
		f.add("zt", zt);
		f.add("obj", tasklogManageService.doLoad(logid,false));
		return m.findPage("/xadmin/work/mytaskWindow");
	}
	
	@RequestMapping("/tuiTaskLog")
	public Page doTuiTaskLog(Form f, Module m) throws Exception {
		TTaskLog obj = (TTaskLog)f.copy2Class(TTaskLog.class);
		TUser userInfo = (TUser) f.getSession("userInfo");
		return m.getWritePage(f, tasklogManageService.doBackTask(obj,userInfo));
	}
}
